import React from 'react';
import { ModifyPassword } from '../components/smart';
import { modifyPassword, resetModifyPassword } from '../actions/changeThePassword';
import ChangeThePasswordStyle from './ChangeThePassword.less';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
function mapStateToProps(state) {

  let { authentication, changeThePassword } = state;

  return {
    authentication,
    changeThePassword
  };
}
export default class ChangeThePassword extends React.Component {
  static propTypes = {
    name: React.PropTypes.string,
  };

  constructor(props) {
    super(props);
  };

  handleSubmit = ({oldPassword,newPassword,securityCode}) => {
    let { dispatch } = this.props;
    let { user } = this.props.authentication;
    let params = {
      oldPassword,
      newPassword,
      securityCode,
      userName:user.mobile
    }
    dispatch(modifyPassword(params))
  }
  handleBack = () => {
    let { dispatch } = this.props;
    dispatch(push('/app/BackToAuthenticate'))
  }
  componentDidMount() {
    let { dispatch } = this.props;
    dispatch(resetModifyPassword())
  }

  render() {
    let { codeArea, user } = this.props.authentication;
    let { actionState, message } = this.props.changeThePassword;
    return (
      <div className={ChangeThePasswordStyle.changePassword}>
      	<b>更改密码</b>
        <div>
      		<ModifyPassword 
            message={message}
            actionState={actionState}
            securityCodeUrl={codeArea.url+user.mobile}
            onBack={this.handleBack}
            onSubmit={this.handleSubmit}
           />
        </div>
      </div>
    );
  }
}
export default connect(mapStateToProps)(ChangeThePassword);